package com.example.service.impl.institutioncare.institutionadmin;

import com.example.bean.carecommunity.SafetySystem;
import com.example.bean.configuration.zhibiaosystem.XzLiebiao;
import com.example.bean.configuration.zhibiaosystem.Zhibiao;
import com.example.bean.institutioncare.institutionadmin.Basicdata;
import com.example.bean.institutioncare.institutionadmin.BasicdataVo;
import com.example.bean.institutioncare.institutionadmin.BasicinformationMessage;
import com.example.mapper.institutioncare.institutionadmin.BasicMapper;
import com.example.service.institutioncare.institutionadmin.BasicService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class BasicServiceImpl implements BasicService{

    @Autowired
    BasicMapper mapper;

    @Override
    public PageInfo<Basicdata> selectPageInfo(BasicdataVo vo){
        int pageNum=vo.getPageNum()==null?1:vo.getPageNum();
        int pageSize=vo.getPageSize()==null?2:vo.getPageSize();
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<Basicdata>(mapper.selectPageInfo(vo));
    }

    @Override
    public List<Basicdata> selectInfo(){
        return mapper.selectInfo();
    }

    @Override
    public List<Zhibiao> addInner(){
        return mapper.addInner();
    }

    @Override
    public List<XzLiebiao> addInners(){
        return mapper.addInners();
    }

    @Override
    public Integer addBasicSafetyInnsss(Basicdata basics,SafetySystem safety,String[] innersss){
        if(basics.getNoid()!=null){
            Integer flag=mapper.addBasicdata(basics);
            safety.setBasicid(basics.getNoid());
            safety.setAddname(basics.getAddpeople());
            System.out.println("-----------------------------------------");
            System.out.println(safety.toString());
            System.out.println("-----------------------------------------");
            mapper.addSafetySystem(safety);
            BasicinformationMessage basicmessage=new BasicinformationMessage();
            for(String noids:innersss){
                XzLiebiao xx=mapper.seachInners(noids);
                basicmessage.setBasicid(basics.getNoid());
                basicmessage.setXzliebiao(xx.getNoid());
                basicmessage.setZhibiao(xx.getZbId());
                mapper.addBasicMessage(basicmessage);
            }
            return flag;
        }
        return 0;
    }

    @Override
    public List<BasicinformationMessage> putBasicdata(String noid){
        return mapper.putBasicdata(noid);
    }

    @Override
    public List<SafetySystem> putSafetym(String noid){
        return mapper.putSafetym(noid);
    }

    @Override
    public Integer updateId(Basicdata basics,SafetySystem safety,String[] innersss){
        if(basics.getNoid()!=null){
            Integer flag=mapper.updaBasicdata(basics);
            safety.setBasicid(basics.getNoid());
            Integer flsg=mapper.updaSafetySystem(safety);
            if(flag==1||flsg==1){
                BasicinformationMessage basicmessage=new BasicinformationMessage();
                mapper.deleteBasicMessage(basics.getNoid());
                for(String noids:innersss){
                    XzLiebiao xx=mapper.seachInners(noids);
                    basicmessage.setBasicid(basics.getNoid());
                    basicmessage.setXzliebiao(xx.getNoid());
                    basicmessage.setZhibiao(xx.getZbId());
                    mapper.addBasicMessage(basicmessage);
                }
                return 1;
            }else{
                return 0;
            }
        }
        return 0;
    }

    @Override
    public Integer delete(String noid){
        return mapper.delete(noid);
    }
}